﻿using System;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Operation.Valid
{
	public class TopologyValidationError
	{
		public TopologyValidationError(TopologyValidationErrors errorType, Coordinate pt)
		{
			this.errorType = errorType;
			if (pt != null)
			{
				this.pt = (Coordinate)pt.Clone();
			}
		}

		public TopologyValidationError(TopologyValidationErrors errorType) : this(errorType, null)
		{
		}

		public Coordinate Coordinate
		{
			get
			{
				return this.pt;
			}
		}

		public TopologyValidationErrors ErrorType
		{
			get
			{
				return this.errorType;
			}
		}

		public string Message
		{
			get
			{
				return TopologyValidationError.errMsg[(int)this.errorType];
			}
		}

		public override string ToString()
		{
			return this.Message + " at or near point " + this.pt;
		}

		private static readonly string[] errMsg = new string[]
		{
			"Topology Validation Error",
			"Repeated Point",
			"Hole lies outside shell",
			"Holes are nested",
			"Interior is disconnected",
			"Self-intersection",
			"Ring Self-intersection",
			"Nested shells",
			"Duplicate Rings",
			"Too few points in geometry component",
			"Invalid Coordinate"
		};

		private readonly TopologyValidationErrors errorType;

		private readonly Coordinate pt;
	}
}
